<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>stomp message html page</title>
    <script src="stomp.min.js"></script>
</head>
<body>
<h1>test stomp message</h1>
<div>
    <input type="text" id="message" placeholder="please input need send msg">
    <button onclick="send_message()">send msg</button>
    <button onclick="send_message_topic()">send topic msg</button>
</div>

<script>
    let client = Stomp.client('ws://127.0.0.1:369/stomp');
    client.connect({}, function (frame) {
        console.log('connect success', frame)
        subscript_channel("test")
    })

    function send_message_topic() {
        let message = document.getElementById("message").value;
        client.send("/topic/greeting", {}, "topic " + message);
    }

    function send_message() {
        let message = document.getElementById("message").value;
        client.send("/app/greeting", {}, message);
    }

    function subscript_channel(channel) {
        client.subscribe(`/user/1/${channel}`, function (response) {
            console.log('接受到消息：', response.body)
        })
    }
</script>
</body>
</html>
